<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.fick.hibernate.model.*"%>
<%@page import="com.fick.hibernate.dao.*"%>
<%
String ip = request.getParameter("ip");
String remark=request.getParameter("remark");

String type = request.getParameter("type");
IpAllowed ipAllowed ;
IpAllowedDAO ipDao = new IpAllowedDAO();
if(type.equals("0")){
	List list = ipDao.findByProperty("ip",ip);
	if(list != null && list.size() != 0 ){
	%>
	<script type="text/javascript">
	<!--
	alert("本IP被加入数据库");
	location.href="managerIp.jsp";
	//-->
	</script>
	<%
	}else{
		ipAllowed = new IpAllowed();
		ipAllowed.setIp(ip);
		ipAllowed.setRemark(remark);
		ipDao.save(ipAllowed);
		%>
		<script type="text/javascript">
			alert("操作成功");
			location.href="managerIp.jsp";
		</script>
		<%
	}
}else if(type.equals("1")){
	String ipallowedid = request.getParameter("ipallowedid");
	Integer id = Integer.parseInt(ipallowedid);
	ipAllowed = ipDao.findById(id);	
	ipAllowed.setIp(ip);
	ipAllowed.setRemark(remark);
	ipDao.update(ipAllowed);
	%>
	<script type="text/javascript">
		alert("操作成功");
		location.href="managerIp.jsp";
	</script>
	<%
}
%>
